#include <stdio.h>
void create_magic_square(int n, char magic_square[n][n]);
void print_magic_square(int n, char magic_square[n][n]);
int main(void)
{
    printf("Tis program creates a magic square of a specified size.\n");
    printf("The size must be an odd number between 1 and 99.\n");
    printf("Enter size of magic square: ");
    int size;
    scanf("%d", &size);
    char square[size][size];
    create_magic_square(size, square);
    print_magic_square(size, square);
    return 0;
}
void create_magic_square(int n, char magic_square[n][n]) {
    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < n; j++)
            magic_square[i][j] = -1;
    }

    int row = 0, column = n / 2;
    for (int i = 1; i <= n * n; i++) {
        magic_square[row][column] = i;
        row = (row + n - 1) % n;
        column = (column + 1) % n;
        if (magic_square[row][column] >= 0) {
            row = (row + 2) % n;
            column = (column + n - 1) % n;
        }
    }
}
void print_magic_square(int n, char magic_square[n][n]) {
    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < n; j++) {
            printf("%5d", magic_square[i][j]);
        }
        printf("\n");
    }
}